<div class="content-titulo">
    
    <h2><?php echo 'Medidas - '.$this->data['GRA_NOM'];?></h2>
</div>

<div class="content-table">
    
    <form method="post" action="" enctype="application/x-www-form-urlencoded">
    <?php
   
    $arr_col = array(); 
    
    $url = $this->urlbase.'/'.$this->modulo.'/'.$this->controller;
    $el = new Zend_Form_Element_Hidden('GRA_ID',array('disableLoadDefaultDecorators' =>true));
    $el->addDecorators(array(array('ViewHelper'),array('Errors')))
        ->setValue($this->data['GRA_ID'])
        ->addFilter('Int');
    echo $el;

    ?>
        
        <table id="tlist" class="tb-gtm"> 
            <thead>
                
                <tr>
                    <th style="background-color: transparent;"></th>
                <?php foreach($this->leg as $key => $led){ 
                    $query = 'SELECT SQL_CACHE LGM_ID,LGM_NOM FROM LEGENDAMEDIDAS WHERE LGM_ID = ' . $led['LGM_ID'];
                    $lgm = $this->db->fetchRow($query);
                    $arr_col[$key] = $led['LGM_ID'];
                ?>
                    <th><?php echo $lgm['LGM_NOM']; ?></th>
                <?php } ?>
                </tr>
                
                <tr>
                    <th>Medida<br>Inicial</th>
                <?php foreach($this->leg as $key => $led){ ?>
                    <th><input type="text" class="float medini medini<?php echo $led['LGM_ID']?>" lgm="<?php echo $led['LGM_ID']?>" name="medini[<?php echo $led['LGM_ID']?>]" value="<?php echo $this->medini[$led['LGM_ID']];?>" /></th>
                <?php } ?>
                </tr>
                
                <tr>
                    <th>Redução<br>Costura</th>
                <?php foreach($this->leg as $key => $led){ ?>
                    <th><input type="text" class="float redcos redcos<?php echo $led['LGM_ID']?>" lgm="<?php echo $led['LGM_ID']?>" name="redcos[<?php echo $led['LGM_ID']?>]" value="<?php echo $this->redcos[$led['LGM_ID']];?>" /></th>
                <?php } ?>
                </tr>
                
                <tr>
                    <th>Ampliação<br>Tamanhos</th>
                <?php foreach($this->leg as $key => $led){ ?>
                    <th><input type="text" class="float amptam amptam<?php echo $led['LGM_ID']?>" lgm="<?php echo $led['LGM_ID']?>" name="amptam[<?php echo $led['LGM_ID']?>]" value="<?php echo $this->amptam[$led['LGM_ID']];?>" /></th>
                <?php } ?>
                </tr>
                
                <tr>
                    <th style="background-color: transparent;"><?php // Tamanho ?></th>
                <?php foreach($this->leg as $key => $led){ 
                    $query = 'SELECT SQL_CACHE LGM_ID,LGM_NOM FROM LEGENDAMEDIDAS WHERE LGM_ID = ' . $led['LGM_ID'];
                    $lgm = $this->db->fetchRow($query);
                    $arr_col[$key] = $led['LGM_ID'];
                ?>
                    <th><?php echo $lgm['LGM_NOM']; ?></th>
                <?php } ?>
                </tr>
            </thead>
            
            <tbody>
                <?php foreach($this->tam as $tm){ 
                    $query = 'SELECT SQL_CACHE TAM_ID,TAM_NOM FROM TAMANHOS WHERE TAM_ID = ' . $tm['TAM_ID'];
                    $tam = $this->db->fetchRow($query);   
                ?>
                    <tr>  
                        <th style="text-align: center;"><?php echo $tam['TAM_NOM']; ?></th> 
                        <?php foreach($arr_col as $col){ 
                            $query = 'SELECT SQL_CACHE GTM_VAL FROM GRADETAMANHOS_HAS_MEDIDAS WHERE GRA_ID = '.$this->data['GRA_ID'].' and TAM_ID = '.$tm['TAM_ID'].' and LGM_ID = '.$col;
                            $r_gtm = $this->db->fetchRow($query);
                        ?>
                        <td><input type="text" class="float lgm<?php echo $col;?>" name="med[<?php echo $tm['TAM_ID']; ?>][<?php echo $col; ?>]" value="<?php echo $r_gtm['GTM_VAL']; ?>" /></td>
                        <?php } ?>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
        
            <br>
        <?php
        

        $btn = new Zend_Form_Element_Submit('submit',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setLabel('Gravar');
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-button btn-ok');
        echo $btn;


        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-button btn-cancel">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-button btn-cancel');
        echo $btn;
        //$form->addElement($btn);

        ?>
    </form>
</div>      
  